package com.miguo.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.miguo.app.AppConfig;
import com.miguo.app.AppContext;

/*
 * SharedPreferences
 * Config存储
 */
public class ApiPrefs {

    private static ApiPrefs instance;

    private SharedPreferences prefs;

    private ApiPrefs() {
        prefs = AppContext.getContext().getSharedPreferences(
                AppConfig.APP_PREFS_CONFIG, Context.MODE_PRIVATE);
    }

    public static ApiPrefs init() {
        if (instance == null) {
            instance = new ApiPrefs();
        }
        return instance;
    }

    /* 初始化状态 */
    public boolean getLock() {
        return prefs.getBoolean("Lock", false);
    }

    /* 初始化状态 */
    public void setLock(boolean isLock) {
        prefs.edit().putBoolean("Lock", isLock).commit();
    }

    /* 清除缓存时间 */
    public long getClearCacheTime() {
        return prefs.getLong("clear_cache_time", 0);
    }

    /* 清除缓存时间 */
    public void setClearCacheTime(long ClearCacheTime) {
        prefs.edit().putLong("clear_cache_time", ClearCacheTime).commit();
    }

    /* 开始时间 */
    public long getStartTime() {
        return prefs.getLong("starttime", 0);
    }

    /* 开始时间 */
    public void setStartTime(long starttime) {
        prefs.edit().putLong("starttime", starttime).commit();
    }

    /* CONFIG 版本标志 */
    public int getConfigVer() {
        return prefs.getInt("config_ver", 1);
    }

    /* CONFIG 版本标志 */
    public void setConfigVer(int ver) {
        prefs.edit().putInt("config_ver", ver).commit();
    }

    /* 版本标志 */
    public int getVersionMark() {
        return prefs.getInt("version_mark", 1);
    }

    /* 版本标志 */
    public void setVersionMark(int mark) {
        prefs.edit().putInt("version_mark", mark).commit();
    }

    /* 屏幕亮度 */
    public int getSysBrightnessMode() {
        return prefs.getInt("brightness_mode", 0);
    }

    /* 屏幕亮度 */
    public void setSysBrightnessMode(int mode) {
        prefs.edit().putInt("brightness_mode", mode).commit();
    }

    /* 屏幕亮度 */
    public int getSysScreenBrightness() {
        return prefs.getInt("screen_brightness", 0);
    }

    /* 屏幕亮度 */
    public void setSysScreenBrightness(int brightness) {
        prefs.edit().putInt("screen_brightness", brightness).commit();
    }

    /* 首屏Logo IMG */
    public String getWelPicUrl() {
        return prefs.getString("welpic", null);
    }

    /* 首屏Logo IMG */
    public void setWelPicUrl(String welpic) {
        prefs.edit().putString("welpic", welpic).commit();
    }

    /* 收藏KEY */
    public String getFavorKey() {
        return prefs.getString("favor_key", null);
    }

    /* 收藏KEY */
    public void setFavorKey(String FavorKey) {
        prefs.edit().putString("favor_key", FavorKey).commit();
    }

    /* 2G3G无图状态 */
    public boolean getNoImgMode() {
        return prefs.getBoolean("noImg_mode", false);
    }

    /* 2G3G无图状态 */
    public void setNoImgMode(boolean isOpen) {
        prefs.edit().putBoolean("noImg_mode", isOpen).commit();
    }

    /* 夜间模式状态 */
    public boolean getNightMode() {
        return prefs.getBoolean("night_mode", false);
    }

    /* 夜间模式状态 */
    public void setNightMode(boolean isOpen) {
        prefs.edit().putBoolean("night_mode", isOpen).commit();
    }

    /* 商品分类缓存时间 */
    public long getCategoryTime() {
        return prefs.getLong("category_time", 0);
    }

    /* 商品分类缓存时间 */
    public void setCategoryTime(long catatime) {
        prefs.edit().putLong("category_time", catatime).commit();
    }

    /* 广告缓存时间 */
    public long getAdvertTime() {
        return prefs.getLong("advert_time", 0);
    }

    /* 广告缓存时间 */
    public void setAdvertTime(long adtime) {
        prefs.edit().putLong("advert_time", adtime).commit();
    }

    /* 用户token */
    public String getUserToken() {
        return prefs.getString("user_token", null);
    }

    /* 用户token */
    public void setUserToken(String token) {
        prefs.edit().putString("user_token", token).commit();
    }

    /**
     * 保存用户登录过期时间
     */
    public void setUserTokenExpiresTime(long time) {
        prefs.edit().putLong("user_token_expires_time", time).commit();
    }

    /**
     * 获取用户登录过期时间
     *
     * @return
     */
    public long getUserTokenExpiresTime() {
        return prefs.getLong("user_token_expires_time", 0);
    }

    /* 签到提醒 */
    public void setSignAlramSwitch(boolean state) {
        prefs.edit().putBoolean("sign_alram_switch", state).commit();
    }

    public boolean getSignAlramSwitch() {
        return prefs.getBoolean("sign_alram_switch", true);
    }

    /* 签到时间 */
    public void setSignTime(String time) {
        prefs.edit().putString("sign_time", time).commit();
    }

    public String getSignTime() {
        return prefs.getString("sign_time", "");
    }

    /* 签到提醒时间 */
    public void setSignAlarmTime(String time) {
        prefs.edit().putString("sign_alarm_time", time).commit();
    }

    public String getSignAlarmTime() {
        return prefs.getString("sign_alarm_time", "");
    }


}
